package com.yellowpage.ca.service;

import java.util.List;
import java.util.Map;

import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.DefaultTransactionDefinition;

import com.yellowpage.white.common.Constants;
import com.yellowpage.white.common.PageRender;
import com.yellowpage.white.dao.QueryAssistantSQL;
import com.yellowpage.white.service.BaseServiceImpl;

import com.yellowpage.ca.data.Function;
import com.yellowpage.ca.dao.FunctionDao;

public class FunctionServiceImpl extends BaseServiceImpl implements FunctionService {
	  private FunctionDao functionDao;
	
	  public void setFunctionDao(FunctionDao functionDao) {
		  this.functionDao = functionDao;
	  }
	
	
	  /* white generate Method */ 
	  public Function getFunction(Long id){
	      return functionDao.get(id);
	  }
	  
    public List<Function> queryFunction(Map queryMap , PageRender pageRender){
        return functionDao.getAll();
    }
    
    public List<Map> queryFunctionByPage(Map queryMap, PageRender pageRender) {		
        
    	QueryAssistantSQL sqlAssistant = baseDao.newQueryAssistantSQL(
				"SELECT a.FUNCTION_ID , a.FUNC_CODE , a.NAME , a.PATH , a.STATUS,  " + 
				"       (select fm.name from CA_FUNC_MODULE fm where fm.func_module_id = a.FUNC_MODULE_ID) as FUNC_MODULE, " +
				"       (select display_name from CA_USER where user_id = a.last_update_user) as last_update_user, " +
			    "       date_format(a.last_update_time,'%Y-%m-%d %T') as last_update_time, " +
			    "       (select display_name from CA_USER where user_id = a.create_user) as create_user," +
			    "       date_format(a.create_time,'%Y-%m-%d %T') as create_time " +
			    "  FROM CA_FUNCTION a WHERE 1=1 ")
				    			.addCondition(" and FUNCTION_ID = :functionId ")
							    			.addCondition(" and FUNC_MODULE_ID = :funcModuleId ")
							    			.addCondition(" and FUNC_CODE like :funcCode ")
							    			.addCondition(" and NAME like :name ")
							    			.addCondition(" and PATH like :path ")
							    			.addCondition(" and STATUS = :status ")
							    ; 	

		List<Map> resultList = sqlAssistant.queryByPage(
				baseDao.getConnection(), queryMap, pageRender);

		return resultList;
	}
    
    
    public void saveFunction(Function function){
        functionDao.save(function);
    }
    
	  public void updateFunction(Function function){
	      functionDao.update(function);
	  }
	  
	  public void delete(List deleteList){
	      functionDao.remove(deleteList);
	  }
	  
	  
	 
	
}	